from flask import Flask, request, jsonify
from flask_cors import CORS
import requests
import tempfile
import os
from flask import send_from_directory
from flask import Flask
import logging
import fitz  # PyMuPDF
from docx import Document
import tempfile
from openai import OpenAI


client = OpenAI(
    api_key = "c27a61cf-658c-4b54-a4e9-d1a4574e6738",
    base_url = "https://ark.cn-beijing.volces.com/api/v3",
)


DEEPSEEK_URL = "https://ark.cn-beijing.volces.com/api/v3"
API_KEY = os.getenv("ARK_API_KEY")

def query_ai(prompt):
    """
    向DeepSeek AI接口发送查询请求
    参数:
        prompt (str): 用户输入的提问内容
        context (list): 上下文信息列表，默认为空列表
    返回:
        dict: 包含AI响应结果的JSON对象
    """
    messages = [{"role": "user", "content": prompt}]
    try:
        response = client.chat.completions.create(
            model='deepseek-r1-250528',
            messages=messages,
            temperature=0
        )
        return response.choices[0].message.content  # 注意属性访问方式变更
    except Exception as e:
        return f"错误：{str(e)}"

query_ai('你好,请介绍下你自己')